﻿<!--
You are free to copy and use this sample in accordance with the terms of the
Apache license (http://www.apache.org/licenses/LICENSE-2.0.html)
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title>Google Earth API Sample</title>
    <script src="http://www.google.com/jsapi?key=ABQIAAAAuPsJpk3MBtDpJ4G8cqBnjRRaGTYH6UMl8mADNa0YKuWNNa8VNxQCzVBXTx2DYyXGsTOxpWhvIG7Djw" type="text/javascript"></script>
    
    <!-- We'll need to walk the DOM looking for features of a certain type later -->
    <script src="http://earth-api-samples.googlecode.com/svn/trunk/lib/kmldomwalk.js" type="text/javascript"></script>

    <script type="text/javascript">
        function addSampleButton(caption, clickHandler) {
            var btn = document.createElement('input');
            btn.type = 'button';
            btn.value = caption;

            if (btn.attachEvent)
                btn.attachEvent('onclick', clickHandler);
            else
                btn.addEventListener('click', clickHandler, false);

            // add the button to the Sample UI
            document.getElementById('sample-ui').appendChild(btn);
        }

        function addSampleUIHtml(html) {
            document.getElementById('sample-ui').innerHTML += html;
        }
    </script>
    <script type="text/javascript">
        var ge;

        var tour = null;

        google.load("earth", "1");

        function init() {
            google.earth.createInstance('map3d', initCallback, failureCallback);

            addSampleButton('Enter Tour', enterTour);
            addSampleButton('Play', playTour);
            addSampleButton('Pause', pauseTour);
            addSampleButton('Stop/Reset', resetTour);
            addSampleButton('Exit Tour', exitTour);
        }

        function initCallback(instance) {
            ge = instance;
            ge.getWindow().setVisibility(true);

            // add a navigation control
            ge.getNavigationControl().setVisibility(ge.VISIBILITY_AUTO);

            // add some layers
            ge.getLayerRoot().enableLayerById(ge.LAYER_BORDERS, true);
            ge.getLayerRoot().enableLayerById(ge.LAYER_ROADS, true);

            // create the tour by fetching it out of a KML file
            var href = 'http://earth-api-samples.googlecode.com/svn/trunk/examples/' +
                 'static/grandcanyon_tour.kmz';

            google.earth.fetchKml(ge, href, function (kmlObject) {
                if (!kmlObject) {
                    // wrap alerts in API callbacks and event handlers
                    // in a setTimeout to prevent deadlock in some browsers
                    setTimeout(function () {
                        alert('Bad or null KML.');
                    }, 0);
                    return;
                }

                // Show the entire KML file in the plugin.
                ge.getFeatures().appendChild(kmlObject);

                // Walk the DOM looking for a KmlTour
                walkKmlDom(kmlObject, function () {
                    if (this.getType() == 'KmlTour') {
                        tour = this;
                        return false; // stop the DOM walk here.
                    }
                });
            });

            document.getElementById('installed-plugin-version').innerHTML =
        ge.getPluginVersion().toString();
        }

        function failureCallback(errorCode) {
        }

        function enterTour() {
            if (!tour) {
                alert('No tour found!');
                return;
            }

            ge.getTourPlayer().setTour(tour);
        }

        function playTour() {
            ge.getTourPlayer().play();
        }

        function pauseTour() {
            ge.getTourPlayer().pause();
        }

        function resetTour() {
            ge.getTourPlayer().reset();
        }

        function exitTour() {
            // just like setBalloon(null)
            ge.getTourPlayer().setTour(null);
        }
    
    </script>
  </head>
  <body onload="init()" style="font-family: arial, sans-serif; font-size: 13px; border: 0;">
    <div id="sample-ui"></div>
    <div id="map3d" style="width: 500px; height: 380px;"></div>
    <br>
    <div>Installed Plugin Version: <span id="installed-plugin-version" style="font-weight: bold;">Loading...</span></div>
  </body>
</html>